home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL1.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15.sea / Scriptable Database 1.0a15 / Application / DBElementTokenIterator.cp / DBElementTokenIterator.cp
Encoding:
Text File  |  1996-02-20  |  5.0 KB  |  139 lines  |  [TEXT/CWIE]

  1.  
  2. #include "DBElementTokenIterator.h"
  3. #include "DBElementToken.h"
  4. #include "DBElement.h"
  5. #include "AbstractSearchSpec.h"
  6. #include "AbstractCollector.h"
  7.  
  8. //--------------------------------------------------------------------------------
  9. // TDBElementTokenIterator::~TDBElementTokenIterator
  10. //--------------------------------------------------------------------------------
  11. TDBElementTokenIterator::~TDBElementTokenIterator()
  12. {
  13. } // TDBElementTokenIterator::~TDBElementTokenIterator
  14.  
  15. //--------------------------------------------------------------------------------
  16. // TDBElementTokenIterator::Reset
  17. //--------------------------------------------------------------------------------
  18. void TDBElementTokenIterator::Reset(const TAETransaction&, Boolean iterationDirection /* = kForwardIteration */)
  19. {
  20.     fIterator.Reset(iterationDirection);
  21. }
  22.  
  23. //--------------------------------------------------------------------------------
  24. // TDBElementTokenIterator::More
  25. //--------------------------------------------------------------------------------
  26. Boolean TDBElementTokenIterator::More(const TAETransaction&) const
  27. {
  28.     return fIterator.More();
  29. }
  30.  
  31. //--------------------------------------------------------------------------------
  32. // TDBElementTokenIterator::Next
  33. //--------------------------------------------------------------------------------
  34. void TDBElementTokenIterator::Next(const TAETransaction&)
  35. {
  36.     fIterator.Next();
  37. }
  38.  
  39. //--------------------------------------------------------------------------------
  40. // TDBElementTokenIterator::Current
  41. //--------------------------------------------------------------------------------
  42. TAbstractScriptableObject* TDBElementTokenIterator::Current(const TAETransaction&)
  43. {
  44.     return new TDBElementToken(fIterator.Current()->DBElementCursor());
  45. }
  46.  
  47. //--------------------------------------------------------------------------------
  48. // TDBElementTokenIterator::CurrentDerivedFromOSLClass
  49. //--------------------------------------------------------------------------------
  50. Boolean TDBElementTokenIterator::CurrentDerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
  51. {
  52.     return TDBElementToken(fIterator.Current()->DBElementCursor()).DerivedFromOSLClass(t, objectClass);
  53. }
  54.  
  55. //--------------------------------------------------------------------------------
  56. // TDBElementTokenIterator::GetNamedElement
  57. //--------------------------------------------------------------------------------
  58. TAbstractScriptableObject* TDBElementTokenIterator::GetNamedElement(const TAETransaction& t, DescType desiredClass, TDescriptor nameDesc)
  59. {
  60.     TAbstractScriptableObject* result = nil;
  61.     
  62.     short oldState = nameDesc.Lock();
  63.     
  64.     //
  65.     // A record iterator is given a reference to the top element of the tree
  66.     // to be iterated over, so we must ask this item's _parent_ to find
  67.     // the element with the name we want. 
  68.     //
  69.     AConst<TDBElement> namedElement = fIteratorOwner->DBElementCursor()->TreeOwner(TTransactionSuite::GetTransactionFromEvent(t))->DBElementCursor()->GetNamedElement(TTransactionSuite::GetTransactionFromEvent(t), nameDesc);
  70.     nameDesc.Unlock(oldState);
  71.     if(namedElement.Exists())
  72.     {
  73.         result = new TDBElementToken(namedElement);
  74.         if(result->DerivedFromOSLClass(t, desiredClass) == false)
  75.         {
  76.             delete result;
  77.             result = nil;
  78.         }
  79.     }
  80.     
  81.     return result;
  82. } // TDBElementTokenIterator::GetNamedElement
  83.  
  84. #if 0
  85.  
  86. //--------------------------------------------------------------------------------
  87. // TDBElementTokenIterator::Contains
  88. //--------------------------------------------------------------------------------
  89. Boolean TDBElementTokenIterator::Contains(TAbstractScriptableObject* objectToTestForMembership)
  90. {
  91.     Boolean isContained = false;
  92.     
  93.     for(this->Reset(); this->More() && (isContained == false); this->Next())
  94.     {
  95.         AConst<TDBRecord> current = fIterator.Current();
  96.  
  97.         // isContained = current ???;    // •••
  98.     }
  99.     
  100.     return isContained;
  101. } // TDBElementTokenIterator::Contains
  102.  
  103. #endif
  104.  
  105. //----------------------------------------------------------------------------------------
  106. // TDBElementTokenIterator::AccessBySearchSpec: 
  107. //----------------------------------------------------------------------------------------
  108. void TDBElementTokenIterator::AccessBySearchSpec(const TAETransaction& t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec)
  109.     {
  110.     TAbstractScriptableObject* resultToken = nil;    
  111.     TAbstractScriptableObject* token = nil;
  112.     OSErr err = noErr;
  113.     
  114.     NOREGISTER(token);
  115.         
  116.     Boolean iterationDirection = collector->CollectorRequest(t, kSearchShouldIterateBackwards) ? kBackwardIteration : kForwardIteration;
  117.     for(this->Reset(t, iterationDirection); this->More(t) && (collector->CollectorRequest(t, kCollectionIsFull) == false); this->Next(t))
  118.         {
  119.         Try
  120.             {
  121.             if(token == nil)
  122.                 token = this->Current(t);
  123.             else
  124.                 ((TDBElementToken*)token)->AssignDifferentElement(fIterator.Current()->DBElementCursor());
  125.             if(searchSpec->Compare(t, token) && (token->DerivedFromOSLClass(t, desiredClass) == true))
  126.                 {
  127.                 collector->AddToCollection(token);
  128.                 token = nil;
  129.                 }
  130.             }
  131.         Catch(err)
  132.             {
  133.             }
  134.         }
  135.  
  136.     if(token != nil)
  137.         token->DisposeDesignator();
  138.     } // TDBElementTokenIterator::AccessBySearchSpec
  139.